package com.qiankun.tang.ui.view;

import android.content.Context;
import android.support.annotation.AttrRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;

import com.common.library.listener.OnAppListener;
import com.common.library.ui.view.NestingRecyclerView;
import com.qiankun.tang.R;
import com.qiankun.tang.beans.VideoSynopsisBean;
import com.qiankun.tang.ui.view.adapter.home.VideoSynopsisAdapter;

import java.util.List;

/**
 * @author txf
 * @Title
 * @package com.qiankun.video.ui
 * @date 2017/6/9 0009
 */

public class VideoSynopsisListWidget extends FrameLayout implements OnAppListener.OnInteractionListener {
    NestingRecyclerView mRecycleListView;
    VideoSynopsisAdapter mVideoSynopsisAdapter;
    public VideoSynopsisListWidget(@NonNull Context context) {
        super(context);init();
    }
    public VideoSynopsisListWidget(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);init();
    }
    public VideoSynopsisListWidget(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
        super(context, attrs, defStyleAttr);init();
    }
    public int dip2px(float dipValue) {
        float scale = getContext().getResources().getDisplayMetrics().density;
        return (int) (dipValue * scale + 0.5f);
    }
    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.view_video_synopsis_list_widget,this);
        mRecycleListView = (NestingRecyclerView) findViewById(R.id.view_VideoSynopsisListWidget_RecyclerView);
        mRecycleListView.setLayoutManager(new LinearLayoutManager(getContext(),LinearLayoutManager.HORIZONTAL,false));
//        mRecycleListView.addItemDecoration(new LinearSpacingItemDecoration(LinearLayoutManager.HORIZONTAL,dip2px(4),true));
        mRecycleListView.setAdapter(mVideoSynopsisAdapter = new VideoSynopsisAdapter(getContext(),this));
    }
    public void setItemDecoration(RecyclerView.ItemDecoration decoration){
        mRecycleListView.addItemDecoration(decoration);
    }
    public void setData(List<VideoSynopsisBean> beans){
        mVideoSynopsisAdapter.setDatas(beans);
        mVideoSynopsisAdapter.notifyDataSetChanged();
    }
    OnItemClickListener l;
    public interface OnItemClickListener{
        void onItemClick(int type,VideoSynopsisBean bean);
    }
    public void addOnItemClickListener(OnItemClickListener l) {
        this.l = l;
    }
    @Override
    public void onInteraction(int type, Object o) {
        if(l!= null){
            l.onItemClick(type, (VideoSynopsisBean) o);
        }
    }
}
